package com.demo.backtemplate.controllers;

import com.demo.backtemplate.models.dto.LoginDTO;
import com.demo.backtemplate.models.dto.RegisterDTO;
import com.demo.backtemplate.models.dto.UserDTO;
import com.demo.backtemplate.service.UserService;
import com.xlf.utility.BaseResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 用户控制器
 */
@Slf4j
@RestController
@RequestMapping("/api/user")
@RequiredArgsConstructor
public class UserController {
    private final UserService userService;

    /**
     * 用户登录
     *
     * @param loginDTO 登录信息
     * @return 登录结果
     */
    @PostMapping("/login")
    public ResponseEntity<BaseResponse<UserDTO>> login(@RequestBody LoginDTO loginDTO) {
        return userService.login(loginDTO);
    }

    /**
     * 获取当前登录用户信息
     *
     * @return 用户信息
     */
    @GetMapping("/info")
    public ResponseEntity<BaseResponse<UserDTO>> getUserInfo() {
        return userService.getUserInfo();
    }

    /**
     * 用户登出
     *
     * @return 登出结果
     */
    @PostMapping("/logout")
    public ResponseEntity<BaseResponse<Void>> logout() {
        return userService.logout();
    }

    /**
     * 用户注册
     *
     * @param registerDTO 注册信息
     * @return 注册结果
     */
    @PostMapping("/register")
    public ResponseEntity<BaseResponse<Void>> register(@RequestBody RegisterDTO registerDTO) {
        return userService.register(registerDTO);
    }
}